#! /usr/bin/env python
#coding=utf-8

class DocBase(object):
    "DOC基类，表示对数据的直接操作封装"

    docname = 'DocBase'

    def __init__(self, user):
        ""
        # doc 需要实现一个动态方法查找法，使用doc操作名
        # 就能够查找到应该调用的处理方法
        self.conn = None
        self.user = user
        self.docdict = {
            'add':self.add,
            'delete':self.delete,
            'change':self.change,
            'select':self.select,
            'free':self.free
            }

    def open_conn(self):
        pass

    def add(self, params):
        pass

    def delete(self, rid):
        pass

    def change(self, params):
        pass

    def select(self, params):
        pass

    def free(self, params):
        pass
    
    def close_conn(self):
        pass
    
    def excute_doc_func(self, docfuncname, params):
        "执行特定方法"
        # 重要的方法，将doc处理名和方法做为参数传入，并且执行执行这个方法
        # 实现uoc和aoc操作的另一种办法，怎么看都比较简单
        if self.docdict.get(docfuncname):
            return self.docdict.get(docfuncname)(params)
        else:
            self.user.log.writeLog('excute doc error ,doc func name: '
                                   + str(docfuncname),
                                   'error')
            return False
